-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converts the teeth amount of a gear to the pitch diameter. #72
base: main
Are you sure you want to change the base?
Conversation
Can we add units to all of the methods please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass feedback
package coppercore.math; | ||
|
||
public class GearConversionFunctions { | ||
public static double pitchPulley3mm(int teeth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per #52 all these functions should return a Distance, which is a unit from wpilib. So that needs to be added to all functions.
Also you'll need to include the following in your build.gradle in the dependencies
block
def wpilibVersion = "2025.1.1-beta-1"
implementation "edu.wpi.first.wpiunits:wpiunits-java:$wpilibVersion"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparing floating point numbers with equality is generally considered bad practice. assertEquals
should have an option to specify an epsilon, and I recommend setting that to 1e-10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use it just provide a third parameter which it the delta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another round of feedback
@@ -52,6 +52,10 @@ dependencies { | |||
|
|||
// This dependency is used internally, and not exposed to consumers on their own compile classpath. | |||
implementation libs.guava | |||
|
|||
|
|||
def wpilibVersion = "2025.1.1-beta-1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should no longer be the beta version
import org.junit.jupiter.api.Test; | ||
|
||
public class GearConversionTest { | ||
private static final double delta = 1 * Math.pow(10.0, -10.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but for reference you can do:
private final double kEpsilon = 1e-10;
Assertions.assertEquals( | ||
12 / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(4), delta); | ||
Assertions.assertEquals( | ||
150 / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(50), delta); | ||
Assertions.assertEquals( | ||
0 / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(0), delta); | ||
Assertions.assertEquals( | ||
21 / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(-7), delta); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this (and other functions) a little cleaner by using arrays and a loop:
final double[] kInputs = {4.0, 50.0, 0.0, -7.0};
final double[] kExpectedOutputs = {12.0, 150.0, 0.0, 21.0};
for (int i = 0; i < kInputs.length; i++) {
Assertions.assertEquals(kExpectedOutputs[i] / (Math.PI), GearConversionFunctions.pitchDiameterFrom3mmPulley(kInputs[i]), delta);
}
This way the test inputs and expected outputs are super clear, and the test is set up in a simple way that is easy to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file actually required? My intuition says no and that it should be deleted. If it is required, it should be upgraded to 2025 though
import static edu.wpi.first.units.Units.*; | ||
|
||
public class GearConversionFunctions { | ||
public static double pitchDiameterFrom3mmPulley(int teeth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions likely will fail to compile since we are returning a Distance
but saying we will return a double
. We should mark this and other functions to return a Distance
No description provided.